// pages/driver/lingjuan/index.js
let api = require("../../../api.js"),
  app = getApp();
let handler = require("../../../utils/function.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: handler.userImg,
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    app.request({
      url: api.coupon_list.index,
      method: 'post',
      data: {
      },
      success: function (res) {
        console.log('结果', res)
        that.setData({
          couponArr: res.data,
          //page:page+1
        })
      }
    })
  },
  receive: function (e) {
    let that = this;
    let disid = e.currentTarget.dataset.id;
    let money = e.currentTarget.dataset.money;
    let pasttime = e.target.dataset.pasttime;
    app.request({
      url: api.coupon_list.receive,
      method: 'post',
      data: {
        id: disid,
      },
      success: function (ress) {
        if (ress.code == 1) {
          wx.showModal({
            title: '提示',
            content: '恭喜你获得' + money + '元红包',
            showCancel: false
          })
          that.onShow();
        } else {
          wx.showModal({
            title: '提示',
            content: ress.msg,
            showCancel: false
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // let that = this;
    // console.log(that.data.page)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})